package com.zhixiang.xaec.action.safebase.weixianzuoye;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.google.gson.Gson;
import com.zhixiang.core.command.QueryFilter;
import com.zhixiang.core.entity.TreeObj;
import com.zhixiang.core.util.String2Array;
import com.zhixiang.core.util.YearGridCrud;
import com.zhixiang.core.web.action.BaseAction;
import com.zhixiang.xaec.entity.safebase.weixianzuoye.WeiXianZuoYeGuanLi;
import com.zhixiang.xaec.service.safebase.weixianzuoye.WeiXianZuoYeGuanLiService;
@Controller
@Scope(value="prototype")
public class WeiXianZuoYeGuanLiAction extends BaseAction
{

    private static final long serialVersionUID = -5941283987367985494L;
    
    @Autowired
    private WeiXianZuoYeGuanLiService weiXianZuoYeGuanLiService;
    
    private WeiXianZuoYeGuanLi weiXianZuoYeGuanLi;
    
    public WeiXianZuoYeGuanLi getWeiXianZuoYeGuanLi()
    {
        return weiXianZuoYeGuanLi;
    }

    public void setWeiXianZuoYeGuanLi(WeiXianZuoYeGuanLi weiXianZuoYeGuanLi)
    {
        this.weiXianZuoYeGuanLi = weiXianZuoYeGuanLi;
    }

    public String list(){
        QueryFilter localQueryFilter=new QueryFilter(getRequest());
        List <WeiXianZuoYeGuanLi>list= weiXianZuoYeGuanLiService.getAll(localQueryFilter);
        setTotalCounts(localQueryFilter.getPagingBean().getTotalItems());
        setResult(list);
        return SUCCESS;
    }
    
    public String get(){
        String id=getRequest().getParameter("id");
        if(StringUtils.isNotEmpty(id)){
        setResult(weiXianZuoYeGuanLiService.get(Long.valueOf(id)));    
        }
        return SUCCESS;
    }
    
    public String delete(){
        try
        {
            String ids[]=getRequest().getParameterValues("ids");
            Long[] longIds = String2Array.stringArrayToLongArray(ids);
            weiXianZuoYeGuanLiService.remove(longIds);
        }
        catch (Exception e)
        {
            setMsg("删除失败");
            setSuccess(false);
        }
        return SUCCESS;
    }
   
    public String save()
    {
        try
        {
            weiXianZuoYeGuanLiService.save(weiXianZuoYeGuanLi);
        }
        catch (Exception e)
        {
            setMsg("保存失败");
            setSuccess(false);
        }
        
        return SUCCESS;
    }
    
    
    //实现年份数的方法
    public String treeLoad(){
        List<TreeObj> treeList=YearGridCrud.treeLoad();
        if(treeList!=null){
            outJsonString(new Gson().toJson(treeList));
        }       
        return SUCCESS;
    }


}
